// 动态规划股票问题
// dp[i]  卖  状态转移方程  迭代
var maxProfit = function (prices) {
    let maxProfit = 0, dp = [];//dpTable
    dp[0] = prices[0]; // 初始值不那么重要
    for (let i = 0; i < prices.length; i++) {
        dp[i] = dp[i - 1] < prices[i] ? dp[i - 1] : prices[i];
        maxProfit = (prices[i] - dp[i]) > maxProfit ? prices[i] - dp[i]
        : maxProfit;
    }
    return maxProfit
}

console.time()
console.log(maxProfit([7, 1, 5, 3, 6, 4]));
console.timeEnd()